home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
CodeTextView.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-27
|
3KB
|
117 lines
#ifndef CodeTextView_First
#ifdef __GNUG__
//pragma once
#pragma interface
#endif
#define CodeTextView_First
#include "TextView.h"
#include "TextFormatter.h"
//---- CodeTextView --------------------------------------------------------
// a TextView for editing programm text
// adds: auto indenting
// highlighting matching brackets
// (double clicking on a bracket selects the text enclosed by the brackets)
class CharStyle;
class CodeTextView: public TextView {
public:
MetaDef(CodeTextView);
CodeTextView(
EvtHandler *eh, Rectangle r, Text *t,
bool wrap= TRUE,
TextViewFlags= eTextViewDefault,
Point border= gBorder,
TViewAlign m= eTViewLeft,
int id= cIdNone
); // for efficency reasons do not set contentRect.extent.x to cFit
//---- formatting of source code
virtual class PrettyPrinter *MakePrettyPrinter(
Text *t, CharStyle *cs, CharStyle *fs, CharStyle *cds, CharStyle *ps
);
void FormatCode();
void SetDefaultStyle();
void SetFont(Font *fp);
//---- controller methods
Command *DoLeftButtonDownCommand(Point, Token, int); // matching brackets
Command *DoKeyCommand(int, Token); // auto indent
Command *DoMenuCommand(int);
Command *DoOtherEventCommand(Point p, Token t);
Command *DoCursorKeyCommand(EvtCursorDir, Token);
void SetAutoIndent(bool);
bool GetAutoIndent();
protected:
bool autoIndent;
Point cursorPos;
CharStyle *commentStyle;
CharStyle *functionStyle;
CharStyle *classDeclStyle;
CharStyle *plainStyle;
void MatchBracketForward(int from, int obracket, int cbracket);
void MatchBracketBackward(int from, int obracket, int cbracket);
void ExitCursorMode();
int CursorPos(int ch, int line, EvtCursorDir d, Point);
void SetupStyles(Font *fp);
};
//---- CodeAnalyzer --------------------------------------------------------
class CodeAnalyzer {
bool inDefine;
int lastComment, prevCh, c;
int braceStack, inString, escape, inClass, line;
int canBeClas, canBeFunction;
void FoundComment(AutoTextIter *next);
void FoundEndOfLineComment(AutoTextIter *next);
void FoundFunctionOrMethod(int at, int lastComment);
void FoundClassDecl(int at);
bool IsClassDecl(int at);
protected:
Text *text;
virtual void Start();
virtual void Comment(int line, int start, int end);
virtual void ClassDecl(int line, int start, int end, char *name);
virtual void Function(
int line, int start, int end, char *name, char *classname
);
virtual void End();
public:
CodeAnalyzer(Text *t);
void Doit();
};
//---- PrettyPrinter --------------------------------------------------------
class PrettyPrinter: public CodeAnalyzer {
class StyledText *stext;
class RunArray *st;
CharStyle *commentStyle;
CharStyle *functionStyle;
CharStyle *classDeclStyle;
CharStyle *plainStyle;
protected:
void Start();
void Comment(int line, int start, int end);
void ClassDecl(int line, int start, int end, char *name);
void Function(int line, int start, int end, char *name, char *classname);
void End();
public:
PrettyPrinter(
Text *t, CharStyle *cs, CharStyle *fs, CharStyle *cds, CharStyle *ps
);
};
#endif